#include "specialgb.h"
#include "dcuinformation.h"

SpecialGB::SpecialGB(QWidget *parent) : QWidget(parent)
{
    setWindowFlags(Qt::FramelessWindowHint);
    setAutoFillBackground(true);
    background = palette();
    background.setBrush(QPalette::Window, QBrush(QPixmap(":/images/defaultUI.png")));
    setPalette(background);

    QPushButton *upBtn = new QPushButton(this);
    upBtn->setText(QString(tr("")));
    upBtn->setFont(QFont(ZITI, 20, QFont::Normal));
    upBtn->setGeometry(QRect(720, 150, 60, 60));
    upBtn->setStyleSheet(
        "QPushButton{border-image: url(:/images/up arrow.png);}"
        "QPushButton:pressed{border-image: url(:/images/上箭头_按压.png);}");

    QPushButton *downBtn = new QPushButton(this);
    downBtn->setText(QString(tr("")));
    downBtn->setFont(QFont(ZITI, 20, QFont::Normal));
    downBtn->setGeometry(QRect(720, 250, 60, 60));
    downBtn->setStyleSheet(
        "QPushButton{border-image: url(:/images/down arrow.png);}"
        "QPushButton:pressed{border-image: url(:/images/下箭头_按压.png);}");

    connect(upBtn, &QPushButton::clicked, this, &SpecialGB::specialGbUISignalforUp);
    connect(downBtn, &QPushButton::clicked, this, &SpecialGB::specialGbUISignalforDown);

    LoopNumberDecrease = new QPushButton(this);
    LoopNumberDecrease->setGeometry(QRect(118, 375, 50, 45));
    LoopNumberDecrease->setStyleSheet(
        "QPushButton{border-image: url(:/images/DecreasePulled.png)}"
        "QPushButton:pressed{border-image: url(:/images/DecreasePushed.png);}");
    connect(LoopNumberDecrease, SIGNAL(clicked()), this, SLOT(DecreaseLoopNumber()));

    LoopNumberIncrease = new QPushButton(this);
    LoopNumberIncrease->setGeometry(QRect(212, 375, 50, 45));
    LoopNumberIncrease->setStyleSheet(
        "QPushButton{border-image: url(:/images/IncreasePulled.png)}"
        "QPushButton:pressed{border-image: url(:/images/IncreasePushed.png);}");
    connect(LoopNumberIncrease, SIGNAL(clicked()), this, SLOT(IncreaseLoopNumber()));

    LoopNumber = new QLabel(this);
    LoopNumber->setText(QString("%1").arg(StationInfo.SpecialGBLoopNumber));
    LoopNumber->setAlignment(Qt::AlignCenter);
    LoopNumber->setFont(QFont(ZITI, 20, QFont::Bold));
    LoopNumber->setGeometry(QRect(168, 375, 45, 45));
    LoopNumber->setStyleSheet("color:white;text-align:center;");

    Loop = new QLabel(this);
    Loop->setText(QString(tr("循环次数")));
    Loop->setFont(QFont(ZITI, 18, QFont::Bold));
    Loop->setGeometry(QRect(10, 375, 105, 50));
    Loop->setStyleSheet("color:white");

    OK = new QPushButton(this);
    OK->setText(QString(tr("停止")));
    OK->setFont(QFont(ZITI, 20, QFont::Normal));
    OK->setGeometry(QRect(393 + 60, 375, 111, 46));
    OK->setStyleSheet(
        "QPushButton{border-image: url(:/images/ButtonPulled.png);color:rgb(19,60,76)}"
        "QPushButton:pressed{border-image: url(:/images/ButtonPushed.png);}");

    playstopflag = new QPushButton(this);
    playstopflag->setText(QString(tr("开始")));
    playstopflag->setFont(QFont(ZITI, 20, QFont::Normal));
    playstopflag->setGeometry(QRect(272 + 50, 375, 111, 46));
    playstopflag->setStyleSheet(
        "QPushButton{border-image: url(:/images/ButtonPulled.png);color:rgb(19,60,76)}"
        "QPushButton:pressed{border-image: url(:/images/ButtonPushed.png);}");

    Cancel = new QPushButton(this);
    Cancel->setText(QString(tr("返回")));
    Cancel->setFont(QFont(ZITI, 20, QFont::Normal));
    Cancel->setGeometry(QRect(515 + 70, 375, 111, 46));
    Cancel->setStyleSheet(
        "QPushButton{border-image: url(:/images/ButtonPulled.png);color:rgb(19,60,76)}"
        "QPushButton:pressed{border-image: url(:/images/ButtonPushed.png);}");
}

void SpecialGB::IncreaseLoopNumber()
{
    if (StationInfo.SpecialGBLoopNumber == 10)
    {
        StationInfo.SpecialGBLoopNumber = 0;
        LoopNumber->setText(QString(tr("+∞")));
    }
    else
    {
        StationInfo.SpecialGBLoopNumber++;
        LoopNumber->setText(QString("%1").arg(StationInfo.SpecialGBLoopNumber));
    }
}

void SpecialGB::DecreaseLoopNumber()
{
    if (StationInfo.SpecialGBLoopNumber == 1)
    {
        StationInfo.SpecialGBLoopNumber = 0;
        LoopNumber->setText(QString(tr("+∞")));
    }
    else if (StationInfo.SpecialGBLoopNumber == 0)
    {
        StationInfo.SpecialGBLoopNumber = 10;
        LoopNumber->setText(QString("%1").arg(StationInfo.SpecialGBLoopNumber));
    }
    else
    {
        StationInfo.SpecialGBLoopNumber--;
        LoopNumber->setText(QString("%1").arg(StationInfo.SpecialGBLoopNumber));
    }
}
